package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.manger.union.UnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_CONSTRUCT_ACTIVE_REWARD, desc = "领取建设活跃度奖励")
public class GetConstructActiveRewardCmd extends AbstractCommand {

	private int constructActive;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		UnionProto.UnionConstructActiveRewardReqMsg reqMsg = UnionProto.UnionConstructActiveRewardReqMsg.parseFrom(packet.getBytes());
		constructActive = reqMsg.getConstructActive();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		String unionUid = player.getUserInfo().getUnionUid();
		UnionInfo unionInfo = CrossUnionMgr.getUnionInfo(unionUid);
		if(null == unionInfo){
			ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
			return;
		}
		UnionMember unionMember = CrossUnionMgr.getUnionMember(unionUid, player.getUserId());
		if(null == unionMember){
			ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
			return;
		}
		player.sendPacket(Protocol.C_UNION_CONSTRUCT_ACTIVE_REWARD, UnionProto.UnionConstructActiveRewardReqMsg.newBuilder().setConstructActive(constructActive));
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0) {
			UnionProto.UnionConstructActiveRewardRespMsg.Builder respMsg = UnionProto.UnionConstructActiveRewardRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_UNION_CONSTRUCT_ACTIVE_REWARD, respMsg);
		}
	}

}
